
$(function () {
    let page = {
        enterpriseInfo: {},
        deviceInfo: {},
        userToken: {},
        areaCode: '', // 保存地区的id
        // lineName: ['建档人数', '血压测量次数', '高血压患者数', '接受治疗人数', '控制达标人数'],
        staticList: {
            'recordCount': {
                value: 0,
                lineName: '其他',
                lineData: []
            },
            'checkCount': {
                value: 0,
                lineName: '皮质癌',
                lineData: []
            },
            'patientCount': {
                value: 0,
                lineName: '库欣综合征',
                lineData: []
            },
        },
        colorList: ['#e14dff', '#ffc44d', '#ff4d4d', '#40ffff', '#4dff88']
    };
    let lineType = 'wek';
    let addCode = 0;
    let isWuHan = false;
    let title = "中国大数据平台"

    // 根据时间戳算出时间
    function timeConvert(timestamp, num) {//num:0 YYYY-MM-DD  num:1  YYYY-MM-DD hh:mm:ss // timestamp:时间戳
        timestamp = timestamp;
        timestamp = timestamp.length == 10 ? timestamp * 1000 : timestamp;
        var date = new Date(timestamp);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        if (num == 0) {
            return y + '-' + m + '-' + d;
        } else {
            return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
        }
    };

    // 获取每周一日期
    function getWeek(begin, end, weekNum) {
        var dateArr = new Array();
        var stimeArr = begin.split("-");//=>["2018", "01", "01"]
        var etimeArr = end.split("-");//=>["2018", "01", "30"]

        var stoday = new Date();
        stoday.setUTCFullYear(stimeArr[0], stimeArr[1] - 1, stimeArr[2]);
        var etoday = new Date();
        etoday.setUTCFullYear(etimeArr[0], etimeArr[1] - 1, etimeArr[2]);

        var unixDb = stoday.getTime();//开始时间的毫秒数
        var unixDe = etoday.getTime();//结束时间的毫秒数

        for (var k = unixDb; k <= unixDe;) {
            let needJudgeDate = msToDate(parseInt(k)).withoutTime;
            //不加这个if判断直接push的话就是已知时间段内的所有日期
            if (new Date(needJudgeDate).getDay() === weekNum) {
                dateArr.push(needJudgeDate);
            }
            k = k + 24 * 60 * 60 * 1000;
        }
        return dateArr;
    };

    //根据毫秒数获取日期
    function msToDate(msec) {
        let datetime = new Date(msec);
        let year = datetime.getFullYear();
        let month = datetime.getMonth();
        let date = datetime.getDate();
        let hour = datetime.getHours();
        let minute = datetime.getMinutes();
        let second = datetime.getSeconds();

        let result1 = year +
            '-' +
            ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
            '-' +
            ((date + 1) < 10 ? '0' + date : date) +
            ' ' +
            ((hour + 1) < 10 ? '0' + hour : hour) +
            ':' +
            ((minute + 1) < 10 ? '0' + minute : minute) +
            ':' +
            ((second + 1) < 10 ? '0' + second : second);

        let result2 = year +
            '-' +
            ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
            '-' +
            ((date + 1) < 11 ? '0' + date : date);

        let result = {
            hasTime: result1,
            withoutTime: result2
        };

        return result;
    };

    // 获取每月日期
    function getDateStr(startDate, endDate, dayLength) {
        let arr = []
        for (var i = 0; ; i++) {
            var getDate = getTargetDate(startDate, dayLength);
            startDate = getDate;
            if (getDate <= endDate) {
                if (start === getDate && getDate.split('-')[2] !== '1') {
                    let temp = getDate.split('-');
                    temp[2] = '1';
                    arr.push(temp.join('-'));
                } else if ((new Date(getDate)).getDate() === 1) {
                    arr.push(getDate);
                }
            } else {
                break;
            }
        }
        return arr;
    };

    // startDate: 开始时间；dayLength：每隔几天，0-代表获取每天，1-代表日期间隔一天
    function getTargetDate(date, dayLength) {
        dayLength = dayLength + 1;
        var tempDate = new Date(date);
        tempDate.setDate(tempDate.getDate() + dayLength);
        var year = tempDate.getFullYear();
        var month = tempDate.getMonth() + 1 < 10 ? "0" + (tempDate.getMonth() + 1) : tempDate.getMonth() + 1;
        var day = tempDate.getDate() < 10 ? "0" + tempDate.getDate() : tempDate.getDate();
        return year + "-" + month + "-" + day;

    };

    // 获取年份日期
    function getDateYear() {
        let arr = []
        let nowDate = new Date().getFullYear()
        for (let a = nowDate - 6; a <= nowDate; a++) {
            arr.push(a)
        }
        return arr
    };
    let start = 0;
    let dateType = {
        wek: 604800000,
        month: 2592000000,
        year: 31104000000,
    };
    let arrAll = [];
    let ageLabel = {
        '0': '0-20岁',
        '1': '21-40岁',
        '2': '41-50岁',
        '3': '51-60岁',
        '4': '61-70岁',
        '5': '70岁以上',
    };
    let levelLabel = {
        '1': 'I级',
        '2': 'II级',
        '3': 'III级',
        '-1': '偏低',
        '0': '正常',
    };
    try {
        page.width = document.body.clientWidth;
        page.height = document.body.clientHeight;
        var domCon = document.getElementById("app");
        domCon.style.width = page.width + "px";
        domCon.style.height = page.height + "px";
        new window.Zlzp({ // 初始化zlzp对象
            onLaunch(resp) {
                window.zlzp = this;
                page.enterpriseInfo = window.zlzp.getEnterpriseInfo();
                page.deviceInfo = window.zlzp.getUserInfo();
                page.userToken = window.zlzp.getUserToken();
            },
            onExit() {
            }
        });
    } catch (e) {

    }
    /*******************************begin 公用方法*****************************************/
    page.createTime = function () {
        let today = new Date(new Date().toLocaleDateString())
        today.setTime(today.getTime())
        // 今天
        page.today = parseTime(today, '{y}{m}{d}');
        let start = new Date(new Date().toLocaleDateString());
        let end = new Date(new Date().toLocaleDateString());
        start.setTime(start.getTime());
        end.setTime(end.getTime());
        // 最近一月
        page.range = [start.setTime(start.getTime() - 3600 * 1000 * 24 * 30), end.setTime(end.getTime())]
    };
    page.ajax_load = function (url, type, params, callback, noToken) {
        // 获取当前地址
        let token = page.userToken.token;
        // let token = '74b47b992b0d4d94a57b5096fc852fe1';
        if (!noToken) {
            url += `?token=${token}`;
        }
        // url = '/api/' + url
        $.ajax({
            url: `/${url}`,
            type: type,
            data: params,
            timeout: 15000,
            contentType: "application/json;utf-8",
            success: function (data) {
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // 错误处理
            },
            complete: function (XMLHttpRequest, status) {
            } // 请求完成后最终执行参数
        });
    };
    /*******************************end 公用方法*****************************************/
    // todo 演示使用测试数据，后期调整
    page.getRangeList = function () {
        let labelList = [
            {name: '武汉市', value1: 2285},
            {name: '宣昌市', value1: 672},
            {name: '荆门市', value1: 631},
            {name: '天门市', value1: 874},
            {name: '仙桃市', value1: 1767},
            {name: '孝感市', value1: 1347},
            {name: '黄冈市', value1: 1204},
            {name: '黄石市', value1: 1197},
            {name: '咸宁市', value1: 1072},
            {name: '潜江市', value1: 638},
        ];
        let labelList2 = [
            {name: '武汉市', value1: 86},
            {name: '宣昌市', value1: 72},
            {name: '荆门市', value1: 60},
            {name: '天门市', value1: 53},
            {name: '仙桃市', value1: 40},
            {name: '孝感市', value1: 35},
            {name: '黄冈市', value1: 28},
            {name: '黄石市', value1: 11},
            {name: '咸宁市', value1: 16},
            {name: '潜江市', value1: 9},
        ];
        labelList.sort(function (a, b) {
            return a.value1 - b.value1
        })
        labelList2.sort(function (a, b) {
            return a.value1 - b.value1
        })
        var demo = STD.eChart.init('patient-bar', false);
        STD.eChart.show(demo, MainChart.barVertical(labelList, 1));
        var demo2 = STD.eChart.init('patient-bar2', false);
        STD.eChart.show(demo2, MainChart.barVertical(labelList2, 2));
        // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = 'e68e6e79afee4e3abb8eef7a3e35cf86';
        // let areaCode = '1000/1016/0001';
        // let url2 = `manager/scientific/statistics/distribution/uvByUser/${enterpriseId}/chushengdi_0001A`;
        // let params = {enterpriseArea: areaCode}
        // page.ajax_load(url2, 'post',JSON.stringify(params), function (res) {
        //     let _code = []
        //     let labelList = []
        //     let __data = res.data || {}
        //     for (let key in __data) {
        //         _code.push(key)
        //     }
        //     let url3 = 'manager/scientific/system/research/labels/list'
        //     page.ajax_load(url3, 'get',{codes: _code.join(',')}, function (res2) {
        //         let __res = res2.data || []
        //         __res.filter(items => {
        //             labelList.push({name:items.name, value1: res.data[items.code]})
        //         })
        //         labelList.sort(function (a,b){return a.value1 - b.value1})
        //         var demo = STD.eChart.init('patient-bar', false);
        //         STD.eChart.show(demo, MainChart.barVertical(labelList));
        //         var demo2 = STD.eChart.init('patient-bar2', false);
        //         STD.eChart.show(demo2, MainChart.barVertical(labelList));
        //     })
        // })
    };

    /*******************************begin 患者数量*****************************************/
    page.inOutHosCount = function () {
        // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        // let url = `manager/scientific/statistics/distribution/recordByCrf/${enterpriseId}/enterpriseId`;
        //
        // let params = {
        //     enterpriseArea: '1000/1016/0001',
        // };
        // page.ajax_load(url, 'post',JSON.stringify(params), function (res) {
        //     let num = 0
        //     if (JSON.stringify(res.data) !== '{}') {
        //         for (let i in res.data) {
        //             num = res.data[i] || 0
        //         }
        //     }
        var options = {
            useEasing: true, // 使用缓和效果
            useGrouping: false, // 使用分组效果
            separator: ',', // 分离器，数据够三位，例如100,000
            decimal: '.', // 小数点分割，例如：10.00
            prefix: '', // 第一位默认数字，例如：¥
            suffix: '' // 最后一位默认数字，例如：元，美元
        }
        let num = 16112;
        if (isWuHan) {
            let enterpriseId = page.enterpriseInfo.id;
            // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
            let url = `manager/scientific/statistics/distribution/recordByCrf/${enterpriseId}/enterpriseId`;

            let params = {
                enterpriseArea: '1000/1016/0001',
            };
            page.ajax_load(url, 'post',JSON.stringify(params), function (res) {
                let num = 0
                if (JSON.stringify(res.data) !== '{}') {
                    for (let i in res.data) {
                        num = res.data[i] || 0
                    }
                }
                let demo = new CountUp('top-item-text-big', 0, num, 0, 3, options)
                if (!demo.error) {
                    demo.start()
                } else {
                    console.error(demo.error)
                }
            })
            // num = 2590;
        }else {
            let demo = new CountUp('top-item-text-big', 0, num, 0, 3, options)
            if (!demo.error) {
                demo.start()
            } else {
                console.error(demo.error)
            }
            num = 16112;
        }

        // });
    };
    /*******************************end 患者数量*****************************************/

    // 病种分布
    // todo 演示使用测试数据，后期调整
    page.getDiseaseAnalyse = function (areaCode) {
        let res = {};
        if (isWuHan) {
            res = {
                'b1': 56,
                'b2': 23,
                'b3': 67,
                'b4': 45,
                'b5': 27,
                'b6': 43,
                'b7': 122
            }
        } else {
             res = {
                'b1': 156,
                'b2': 31,
                'b3': 167,
                'b4': 145,
                'b5': 127,
                'b6': 143,
                'b7': 222
            }
        }
        let labelList = {
            b1: '原发性醛固酮增多症',
            b2: '皮质癌',
            b3: '嗜铬细胞瘤',
            b4: '无功能腺癌',
            b5: '库欣综合征',
            b6: '髓质脂肪癌',
            b7: '其他'
        }
        var demo2 = STD.eChart.init('main-bottom-canvas2', false);
        STD.eChart.show(demo2, MainChart.barGradual(res, labelList));
        // areaCode = '1000/1016/0001';
        // var demo2 = STD.eChart.init('main-bottom-canvas2', false);
        // // STD.eChart.show(demo2, MainChart.barGradual());
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = 'e68e6e79afee4e3abb8eef7a3e35cf86';
        // let url = `manager/scientific/statistics/distribution/recordByUser/${enterpriseId}/chuyuanzd_0433A`;
        //
        // let params = {
        //     enterpriseArea: areaCode,
        // };
        // page.ajax_load(url, 'post',JSON.stringify(params), function (res) {
        //     if (JSON.stringify(res.data) === '{}') {
        //         this.showCanvas = false
        //         if (demo2) {
        //             demo2.clear()
        //         }
        //         return
        //     }
        //     let _code = []
        //     let labelList = {}
        //     let __data = res.data || {}
        //     for (let key in __data) {
        //         _code.push(key)
        //     }
        //     let url2 = 'manager/scientific/system/research/labels/list'
        //     page.ajax_load(url2, 'get',{codes: _code.join(',')}, function (res2) {
        //         let __res = res2.data || []
        //         __res.filter(items => {
        //             labelList[items.code] = items.name
        //         })
        //         STD.eChart.show(demo2, MainChart.barGradual(res.data, labelList));
        //     })
        // });
    };
    // 新增病例
    page.getDiseaseAnalyseList = function (areaCode, apiType, type) {
        areaCode = '1000/1016/0001';
        // var demo2 = STD.eChart.init('main-bottom-canvas', false);
        // STD.eChart.show(demo2, MainChart.barGradual());
        // let enterpriseId = page.enterpriseInfo.id;
        let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        let url = `manager/scientific/statistics/temporalDay/recordByUser/${enterpriseId}`;
        let eDate = new Date().getTime()
        let sDate = new Date().getTime() - dateType['year']
        let params1 = {
            enterpriseArea: areaCode,
            bdate: sDate,
            edate: eDate,
            andCompareValue: ['chuyuanzd_0433A==2000/0001a/0001a7']
        };
        switch (apiType) {
            case 'b1':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a1']
                break
            case 'b2':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a2']
                break
            case 'b3':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a3']
                break
            case 'b4':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a4']
                break
            case 'b5':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a5']
                break
            case 'b6':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a6']
                break
            case 'b7':
                params1.andCompareValue = ['chuyuanzd_0433A==2000/0001a/0001a7']
                break
        }
        return new Promise((resolve, reject) => {
            page.ajax_load(url, 'post', JSON.stringify(params1), function (res) {
                resolve(res.data)
                // STD.eChart.show(demo2, MainChart.barGradual(res.data, labelList));
            });
        })
    };
    page.getBings = function (type) {
        let dataX = []
        let eDate = timeConvert(new Date().getTime(), 0);
        let sDate = timeConvert((new Date().getTime() - dateType['year']), 0);
        start = timeConvert((new Date().getTime() - dateType['year'] + 86400000), 0);
        if (type === 'wek') {
            dataX = getWeek(sDate, eDate, 1);
        } else if (type === 'month') {
            dataX = getDateStr(sDate, eDate, 0);
        } else {
            dataX = getDateYear();
        }
        return Promise.all([
            page.getDiseaseAnalyseList('', 'b1', type),
            page.getDiseaseAnalyseList('', 'b2', type),
            page.getDiseaseAnalyseList('', 'b3', type),
            page.getDiseaseAnalyseList('', 'b4', type),
            page.getDiseaseAnalyseList('', 'b5', type),
            page.getDiseaseAnalyseList('', 'b6', type),
            page.getDiseaseAnalyseList('', 'b7', type),
        ]).then(res => {
            arrAll = [
                {data: res[0], num: 0, name: 'b1'},
                {data: res[1], num: 0, name: 'b2'},
                {data: res[2], num: 0, name: 'b3'},
                {data: res[3], num: 0, name: 'b4'},
                {data: res[4], num: 0, name: 'b5'},
                {data: res[5], num: 0, name: 'b6'},
                {data: res[6], num: 0, name: 'b7'},
            ];
            res.forEach((item, index) => {
                let num = 0;
                item.forEach(item2 => {
                    num += item2.num || 0
                })
                arrAll[index]['num'] = num
            })
            arrAll.sort(function (a, b) {
                return b.num - a.num
            })

            // for (let a = 0; a < 3; a++) {
            //     arrAll[a].data.forEach((item, index) => {
            //         // debugger
            //         arrAll[a]['dataY'] = []
            //         console.log(item)
            //         dataX.forEach((item2, index2) => {
            //             let temp = parseInt(item2.replaceAll('-',''))
            //             let temp2 = 0
            //             if (index2 === dataX.length - 1) {
            //                 temp2 = parseInt(dataX[index2].replaceAll('-','')) + 7
            //             } else {
            //                 temp2 = parseInt(dataX[index2+1].replaceAll('-',''))
            //             }
            //             let temp1 = parseInt(item._id)
            //             if (temp<=temp1 && temp2 > temp1) {
            //                 // console.log(item.num)
            //                 arrAll[a]['dataY'].push(item.num)
            //                 if (index === 0) {
            //                     arrAll[a]['dataY'].push(item.num)
            //                 } else {
            //                     // arrAll[a]['dataY'][index2](item.num)
            //                 }
            //             } else {
            //                 if (index === 0) {
            //                     arrAll[a]['dataY'].push(0)
            //                 }
            //             }
            //         })
            //     })
            // }
        })
    }

    /*******************************begin 患者趋势*****************************************/
    page.getData = function (apiType) {
        let enterpriseId = page.enterpriseInfo.id;
        let url = ''
        switch (apiType) {
            case 'recordCount': // 建档总人数
                url = `manager/scientific/statistics/completion/crf/${enterpriseId}`;
                break
            case 'checkCount': // 血压测量总次数
                url = `manager/medical/statistics/check_count/${enterpriseId}/bloodpress`;
                break
            case 'patientCount': // 高血压患者数
                url = `manager/medical/statistics/patient_count/${enterpriseId}/hypertension`;
                break
            case 'curedCount': // 接受治疗人数
                url = `manager/medical/statistics/cured_count/${enterpriseId}`;
                break
            case 'controlCount': // 控制达标人数
                url = `manager/medical/statistics/control_count/${enterpriseId}/hypertension`;
                break
        }
        let params = {
            startTime: parseTime(page.range[0], '{y}{m}{d}'),
            endTime: parseTime(page.range[1], '{y}{m}{d}')
        };
        return new Promise((resolve, reject) => {
            let params = {};
            if (apiType === 'recordCount') {
                if (isWuHan) {
                    params[apiType] = {
                        '20201102': [5, 5],
                        '20201103': [8, 3],
                        '20201104': [12, 4],
                        '20201105': [19, 7],
                        '20201106': [25, 6],
                    }
                } else {
                    params[apiType] = {
                        '20201102': [15, 15],
                        '20201103': [18, 13],
                        '20201104': [22, 14],
                        '20201105': [29, 17],
                        '20201106': [35, 16],
                    }
                }

            } else if (apiType === 'checkCount') {
                if (isWuHan) {
                    params[apiType] = {
                        '20201102': [4, 4],
                        '20201103': [6, 2],
                        '20201104': [7, 1],
                        '20201105': [12, 5],
                        '20201106': [13, 1],
                        '20201111': [15, 2],
                    }
                } else {
                    params[apiType] = {
                        '20201102': [14, 14],
                        '20201103': [16, 12],
                        '20201104': [17, 11],
                        '20201105': [22, 15],
                        '20201106': [23, 11],
                        '20201111': [25, 12],
                    }
                }

            } else {
                if (isWuHan) {
                    params[apiType] = {
                        '20201102': [0, 0],
                        '20201103': [1, 1],
                        '20201104': [4, 3],
                        '20201105': [5, 1],
                        '20201106': [9, 4],
                        '20201107': [11, 2],
                        '20201108': [12, 1],
                        '20201109': [15, 3],
                    }
                } else {
                    params[apiType] = {
                        '20201102': [10, 10],
                        '20201103': [11, 11],
                        '20201104': [14, 13],
                        '20201105': [15, 11],
                        '20201106': [19, 14],
                        '20201107': [21, 21],
                        '20201108': [22, 11],
                        '20201109': [25, 13],
                    }
                }
            }
            resolve(params)
        });
    };
    page.loadData = function (isChange) {
        // isChange 值为true是为切换日期，不更新治疗概况
        let startTime = parseTime(page.range[0], '{y}{m}{d}');
        let endTime = parseTime(page.range[1], '{y}{m}{d}')
        return Promise.all([
            page.getData('recordCount'),
            page.getData('checkCount'),
            page.getData('patientCount'),
            page.getData('curedCount'),
            page.getData('controlCount'),
        ]).then(res => {
            let result = res || [];
            // 先获取横坐标的值，保证折线图无断点（接口返回的诗句日期可能会有断点，前端兼容）
            let xValue = page.getXvalue(result);
            result.filter((options, index) => {
                for (let k in options) {
                    let items = options[k];
                    if (JSON.stringify(items) === '{}') {
                        items[startTime] = [0, 0]
                        items[endTime] = [0, 0]
                    }
                    page.staticList[k] ? page.staticList[k].lineData = [] : null;
                    xValue.filter(values => {
                        let _key = values.replace(/-/g, '');
                        let _value = items[_key] || [];
                        page.staticList[k] ? page.staticList[k].lineData.push(_value[1] || 0) : null
                    });
                }
            });
            // xValue 排序
            if (isChange === 'mon') {
                xValue = ['2020-9', '2020-10', '2020-11', '2020-12', '2021-1', '2021-2', '2021-3']
            } else if (isChange === 'year') {
                xValue = ['2015', '2016', '2017', '2018', '2019', '2020', '2021']
            } else {
                xValue = ['2021-01-25', '2021-02-01', '2021-02-08', '2021-02-15', '2021-02-22', '2021-03-01', '2021-03-08']
            }
            xValue.sort(compare());
            page.createLine(xValue);
        })
    };
    // 获取横坐标
    page.getXvalue = function (result) {
        let xValue = []
        let startTime = parseTime(page.range[0], '{y}{m}{d}');
        let endTime = parseTime(page.range[1], '{y}{m}{d}');
        result.filter(options => {
            for (let k in options) {
                let items = options[k];
                if (JSON.stringify(items) === '{}') {
                    items[startTime] = [0, 0]
                    items[endTime] = [0, 0]
                }
                let amount = [];
                for (let l in items) {
                    let _date = formatDate(l, '{y}-{m}-{d}');
                    items[l][0] && amount.push(items[l][0])
                    if (xValue.indexOf(_date) == -1) {
                        xValue.push(_date)
                    }
                }
                page.staticList[k] ? page.staticList[k].value = amount[amount.length - 1] : null
            }
        });
        // xValue 排序
        xValue.sort(compare());
        return xValue;
    };
    // 病种新增折线图
    page.createLine = function (xValue) {
        let listData = [];
        let lineName = [];
        let _index = 0;
        for (let k in page.staticList) {
            let item = page.staticList[k];
            lineName.push(item.lineName);
            listData.push(
                {
                    data: item.lineData,
                    type: 'line',
                    name: item.lineName || "",
                    smooth: true,
                    symbolSize: 1,
                    areaStyle: {
                        normal: {
                            // color: page.colorList[_index],
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1,//变化度
                                //三种由深及浅的颜色
                                [{
                                    offset: 0,
                                    color: page.colorList[_index]
                                },
                                    //     {
                                    //     offset : 0.5,
                                    //     color : '#267268'
                                    // },
                                    {
                                        offset: 1,
                                        color: '#14323f'
                                    }]),
                            opacity: 0.2,
                        }
                    },
                    itemStyle: {
                        normal: {
                            lineStyle: {
                                color: page.colorList[_index],
                            }
                        },
                    }
                }
            );
            _index++;
        }
        var demo = STD.eChart.init('main-bottom-canvas', false);
        STD.eChart.show(demo, MainChart.line(listData, xValue, lineName, page.colorList));
        // let option = MainChart.line(listData, xValue, lineName, page.colorList);
    };
    //概率图
    page.createRate = function (data) {
        // 知晓率
        let awarenessScale = data.patientCount.value > 0 && data.recordCount.value > 0 ? ((data.patientCount.value / data.recordCount.value)).toFixed(2) : 0
        // this.waveData.awareness.scale = awarenessScale
        // page.createCircle(1, awarenessScale, 'awareness');
        // 治愈率
        let cureScale = data.curedCount.value > 0 && data.controlCount.value > 0 ? ((data.controlCount.value / data.curedCount.value)).toFixed(2) : 0
        // this.waveData.cure.scale = cureScale
        // page.createCircle(1, cureScale, 'cure');
        // 控制率
        let controlScale = data.curedCount.value > 0 && data.controlCount.value > 0 ? ((data.controlCount.value / data.curedCount.value) * 100).toFixed(2) : 0
        // this.waveData.control.scale = controlScale
        // page.createCircle(1, 0.67, 'control');
    };
    page.createCircle = function (miletargetTarmileage, progress, pieType) {
        var canvasWidth = ($("#" + pieType + "-Canvas").width()) * 0.8;
        // var canvasHeight = $("#"+pieType+"-Canvas").height();
        var canvasHeight = canvasWidth * 1.2;
        var canvas = document.getElementById(pieType + "-Canvas"); //画布对象
        canvas.width = canvasWidth;
        canvas.height = canvasHeight;
        var ctx = canvas.getContext('2d');
        //var progress = 50; 当前已加载的进度
        var progressPercent = progress * 100 / miletargetTarmileage;
        if (miletargetTarmileage <= 0) {
            progressPercent = 100;
        }
        ;
        if (progress == 0) {
            progressPercent = 0;
        }

        function canvastxt(progress, progressPercent) {
            ctx.lineWidth = 14;
            ctx.strokeStyle = 'rgb(30, 38, 51)';
            ctx.clearRect(0, 0, canvasWidth, canvasHeight); //清除已绘制内容
            ctx.beginPath();
            ctx.arc(canvasWidth / 2, canvasHeight / 2, 45, 0, 180);
            ctx.stroke(); //对路径进行描边
            ctx.closePath();
            var txtday = progressPercent;
            ctx.font = '34px electronicFont';
            ctx.fillStyle = '#fff';
            var txtdayWidth = ctx.measureText(txtday).width;
            ctx.fillText(txtday, canvasWidth / 2 - txtdayWidth / 2 - 5, canvasHeight / 2 + 10); //绘制进度提示文字
            //写“%”
            var txtkm = "%";
            ctx.font = '13px 微软雅黑';
            ctx.lineWidth = 1;
            var txtkmWidth = ctx.measureText(txtkm).width;
            ctx.fillText(txtkm, canvasWidth / 2 + txtdayWidth / 2 - 2, canvasHeight / 2 + 10);
            var d = 0;
            ctx.lineWidth = 12;
            if (progressPercent >= 100) {
                ctx.beginPath();
                if (pieType === 'cure') {
                    ctx.strokeStyle = 'rgb(0,255,0)';
                } else if (pieType === 'awareness') {
                    ctx.strokeStyle = 'rgb(0,255,255)';
                } else if (pieType === 'control') {
                    ctx.strokeStyle = 'rgb(255,196,0)';
                } else {
                    ctx.strokeStyle = 'rgb(255,100,100)';
                }
                ctx.lineWidth = 12;
                var startAngle = -90 * Math.PI / 180;
                var endAngle = (-90 + 360 * progressPercent / 100) * Math.PI / 180;
                ctx.arc(canvasWidth / 2, canvasHeight / 2, 45, startAngle, endAngle);
                ctx.stroke();
            } else {
                var timer = setInterval(function () {
                    //ctx.clearRect(0,0,canvasWidth,canvasHeight);
                    ctx.beginPath();
                    var startAngle = (-90 + 360 * (d++) / 500) * Math.PI / 180;
                    var endAngle = (-90 + 360 * d / 500) * Math.PI / 180;
                    ctx.arc(canvasWidth / 2, canvasHeight / 2, 45, startAngle, endAngle);
                    if (pieType === 'cure') {
                        ctx.strokeStyle = "rgb(" + (255 - d * 0.5) + ",255," + (255 - d * 0.5) + "," + (d * 0.005) + ")";
                    } else if (pieType === 'awareness') {
                        ctx.strokeStyle = "rgb(" + (255 - d * 0.5) + ",255," + (255) + "," + (d * 0.005) + ")";
                    } else if (pieType === 'control') {
                        ctx.strokeStyle = "rgb(" + (255) + ",196," + (196 - d * 0.5) + "," + (d * 0.005) + ")";
                    } else {
                        ctx.strokeStyle = "rgb(" + (255) + "," + (120 - d * 0.01) + "," + (120 - d * 0.01) + "," + (d * 0.005) + ")";
                    }
                    ctx.stroke();
                    // console.log(progressPercent);
                    // console.log(d);
                    if (d > progressPercent * 5) {
                        clearInterval(timer);
                    }
                });
            }
        }

        canvastxt(progress, progressPercent.toFixed(0));
    }

    /*******************************end 患者趋势*****************************************/

    /*******************************begin 患者分布*****************************************/
    // 年龄分布
    page.getAgeData = function (areaCode) {
        // areaCode = '1000/1016/0001';
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        // let url = `manager/scientific/statistics/distribution/recordByUser/${enterpriseId}/nianlingduan_0001`;
        // let params = {
        //     enterpriseArea: areaCode,
        // };
        // page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
        //     let seriesData = []
        //     let _data = res.data
        //     let ageData = {}
        //     for (let key in _data) {
        //         let age = key.substring(0, 1)
        //         switch (age) {
        //             case '0':
        //                 ageData['0'] = _data[key]
        //                 break
        //             case '1':
        //                 ageData['0'] = ageData['0'] + _data[key]
        //                 break
        //             case '2':
        //                 ageData['1'] = _data[key]
        //                 break
        //             case '3':
        //                 ageData['1'] = ageData['1'] + _data[key]
        //                 break
        //             case '4':
        //                 ageData['2'] = _data[key]
        //                 break
        //             case '5':
        //                 ageData['3'] = _data[key]
        //                 break
        //             case '6':
        //                 ageData['4'] = _data[key]
        //                 break
        //             case '7':
        //                 ageData['5'] = _data[key]
        //                 break
        //             default:
        //                 ageData['5'] = ageData['5'] + _data[key]
        //                 break
        //         }
        //     }
        //     for (let k in ageLabel) {
        //         seriesData.push({
        //             value: ageData[k] || 0,
        //             name: ageLabel[k]
        //         })
        //     }
        let seriesData = []
        if (isWuHan) {
            areaCode = '1000/1016/0001';
            let enterpriseId = page.enterpriseInfo.id;
            // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
            let url = `manager/scientific/statistics/distribution/recordByUser/${enterpriseId}/nianlingduan_0001`;
            let params = {
                enterpriseArea: areaCode,
            };
            page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
                let seriesData = []
                let _data = res.data
                let ageData = {}
                for (let key in _data) {
                    let age = key.substring(0, 1)
                    switch (age) {
                        case '0':
                            ageData['0'] = _data[key]
                            break
                        case '1':
                            ageData['0'] = ageData['0'] + _data[key]
                            break
                        case '2':
                            ageData['1'] = _data[key]
                            break
                        case '3':
                            ageData['1'] = ageData['1'] + _data[key]
                            break
                        case '4':
                            ageData['2'] = _data[key]
                            break
                        case '5':
                            ageData['3'] = _data[key]
                            break
                        case '6':
                            ageData['4'] = _data[key]
                            break
                        case '7':
                            ageData['5'] = _data[key]
                            break
                        default:
                            ageData['5'] = ageData['5'] + _data[key]
                            break
                    }
                }
                for (let k in ageLabel) {
                    seriesData.push({
                        value: ageData[k] || 0,
                        name: ageLabel[k]
                    })
                }
                let demo = STD.eChart.init('center-item-age', false);
                STD.eChart.show(demo, MainChart.pieP('', seriesData));
            })
            // seriesData = [
            //     {value: 10, name: "0-20岁"},
            //     {value: 33, name: "21-40岁"},
            //     {value: 56, name: "41-50岁"},
            //     {value: 105, name: "51-60岁"},
            //     {value: 34, name: "61-70岁"},
            //     {value: 25, name: "70岁以上"}
            //     ]
        }else {
            seriesData = [
                {value: 110, name: "0-20岁"},
                {value: 133, name: "21-40岁"},
                {value: 156, name: "41-50岁"},
                {value: 255, name: "51-60岁"},
                {value: 134, name: "61-70岁"},
                {value: 125, name: "70岁以上"}
            ]
            let demo = STD.eChart.init('center-item-age', false);
            STD.eChart.show(demo, MainChart.pieP('', seriesData));
        }

        // })
    };
    // 性别分布
    page.getSexData = function (areaCode) {
        // areaCode = '1000/1016/0001';
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = 'e68e6e79afee4e3abb8eef7a3e35cf86';
        // let url = `manager/scientific/statistics/distribution/recordByUser/${enterpriseId}/xingbie_0010A`;
        // let params = {
        //     enterpriseArea: areaCode,
        // };
        // let seriesData = []
        // page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
        //     for (let k in res.data) {
        //         seriesData.push({
        //             value: res.data[k] || 0,
        //             name: k
        //         })
        //     }
        let seriesData = []
        if (isWuHan) {
            areaCode = '1000/1016/0001';
            let enterpriseId = page.enterpriseInfo.id;
            // let enterpriseId = 'e68e6e79afee4e3abb8eef7a3e35cf86';
            let url = `manager/scientific/statistics/distribution/recordByUser/${enterpriseId}/xingbie_0010A`;
            let params = {
                enterpriseArea: areaCode,
            };
            let seriesData = []
            page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
                for (let k in res.data) {
                    seriesData.push({
                        value: res.data[k] || 0,
                        name: k
                    })
                }
                let demo2 = STD.eChart.init('center-item-sex', false);
                STD.eChart.show(demo2, MainChart.pieP({color: ['#fc2a53', '#0591dd']}, seriesData));
            })
            // seriesData = [
            //     {value: 1200, name: "男"},
            //     {value: 1390, name: "女"},
            // ]
        }else {
            seriesData = [
                {value: 1340, name: "男"},
                {value: 1900, name: "女"},
            ]
            let demo2 = STD.eChart.init('center-item-sex', false);
            STD.eChart.show(demo2, MainChart.pieP({color: ['#fc2a53', '#0591dd']}, seriesData));
        }

        // })
    };
    // 信息完整度
    page.getDataIntegrity = function (areaCode) {
        // areaCode = '1000/1016/0001';
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        // let url = `manager/scientific/statistics/completion/crf/${enterpriseId}`;
        // let params = {
        //     enterpriseArea: areaCode,
        // };
        // let param = 0
        // page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
        //     let __res = res.data || {}
        //     let valueCount = __res.valueCount || 0 // 总共填写的字段
        //     let fieldCount = __res.fieldCount || 0 // 需要填写的字段
        //     let __value = 0 // 完成率
        //     if (fieldCount && valueCount) {
        //         __value = ((valueCount / fieldCount)).toFixed(2)
        //     }
        //     param = __value
        let param = 0.78;
        if (isWuHan) {
            areaCode = '1000/1016/0001';
            let enterpriseId = page.enterpriseInfo.id;
            // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
            let url = `manager/scientific/statistics/completion/crf/${enterpriseId}`;
            let params = {
                enterpriseArea: areaCode,
            };
            let param = 0
            page.ajax_load(url, 'post', JSON.stringify(params), function (res) {
                let __res = res.data || {}
                let valueCount = __res.valueCount || 0 // 总共填写的字段
                let fieldCount = __res.fieldCount || 0 // 需要填写的字段
                let __value = 0 // 完成率
                if (fieldCount && valueCount) {
                    __value = ((valueCount / fieldCount)).toFixed(2)
                }
                param = __value
                page.createCircle(1, param, 'awareness');
            })
            // param = 0.75
        } else {
            param = 0.78
            page.createCircle(1, param, 'awareness');
        }

        // })
    };
    // 手术率
    page.getOperationRate = function (areaCode) {
        // areaCode = '1000/1016/0001';
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        // let url1 = `manager/scientific/statistics/distribution/uvByUser/${enterpriseId}/shoushurq_0347A`;
        // let url2 = `manager/scientific/statistics/distribution/uvByUser/${enterpriseId}/sfcczy_0600A`;
        // let params = {enterpriseArea: areaCode || '', andCompareValue: [`shoushurq_0347A!=''`]}
        // let params2 = {enterpriseArea: areaCode || '', andCompareValue: ['sfcczy_0600A==是']}
        // page.ajax_load(url1, 'post', JSON.stringify(params), function (res) {
        //     page.ajax_load(url2, 'post', JSON.stringify(params2), function (res2) {
        //         let fParam = 0
        //         let sParam = 0
        //         for (let i in res.data) {
        //             fParam += res.data[i]
        //         }
        //         for (let i in res2.data) {
        //             sParam += res2.data[i]
        //         }
        //         let result = ((fParam / sParam).toFixed(2)) || 0
        let result = 0.58;
        if (isWuHan) {
            result = 0.86
        } else {
            result = 0.58
        }
                page.createCircle(1, result === "NaN" ? 0 : result, 'cure');
            // })
        // })
    };
    // 高血压治愈率
    page.getHypertension = function (areaCode) {
        // areaCode = '1000/1016/0001';
        // // let enterpriseId = page.enterpriseInfo.id;
        // let enterpriseId = '0fb7a16f73f044ef815621ef3aa263b6';
        // let url1 = `manager/scientific/statistics/distribution/uvByUser/${enterpriseId}/shgxyzy_0568A`;
        // let url2 = `manager/scientific/statistics/distribution/uvByUser/${enterpriseId}/shoushurq_0347A`;
        // let params = {
        //     enterpriseArea: areaCode,
        //     andCompareValue: ['shgxyzy_0568A==是']
        // };
        // let params2 = {enterpriseArea: areaCode, andCompareValue: [`shoushurq_0347A!=''`]};
        // let seriesData = []
        // page.ajax_load(url1, 'post', JSON.stringify(params), function (res) {
        //     page.ajax_load(url2, 'post', JSON.stringify(params2), function (res2) {
        //         let fParam = 0
        //         let sParam = 0
        //         for (let i in res.data) {
        //             fParam += res.data[i]
        //         }
        //         for (let i in res2.data) {
        //             sParam += res2.data[i]
        //         }
        //         let result = (fParam / sParam).toFixed(2);
        let result = 0.65;
        if (isWuHan) {
            result = 0.55
        } else {
            result = 0.65
        }
                page.createCircle(1, result === "NaN" ? 0 : result, 'control');
            // })
        // })
    };
    // page.getBings('wek');
    page.getAgeData()
    page.getSexData()
    page.inOutHosCount(); // 患者总数
    page.getDiseaseAnalyse();
    page.getDataIntegrity()
    page.getOperationRate()
    page.getHypertension()
    page.getRangeList()

    setInterval(function () {
        page.getAgeData()
        page.getSexData()
        page.getDiseaseAnalyse();
        page.getDataIntegrity()
        page.getOperationRate()
        page.getHypertension()
        page.loadData(lineType);
        page.getRangeList()
    }, 120000)
    /*******************************end 患者分布*****************************************/

    /*******************************begin 地图*****************************************/
    var timeTicket = null, timeTicketOut = null;
    page.areaDraw = function (data) {
        var mycharts = echarts.init(document.getElementById('map-container'))
        var option = {
            //左下角lengend
            dataRange: {
                show: false,
                x: 'left',
                y: 'bottom',
                splitList: [
                    {start: 5, end: 5, color: '#0675fc'},//当值为5时，区域背景
                    {start: 10, end: 10, color: '#0675fc'},//当值为10时，区域背景
                    {start: 15, end: 15, color: '#57bedb'},//当值为15时，区域背景
                ],
                //左下值域文字样式
                textStyle: {
                    color: '#ff6300'          // 值域文字颜色
                }
            },
            //鼠标悬浮tip
            tooltip: {
                show: false,
                trigger: 'item',
                "confine": true,//是否一直在画布内
                showContent: false,//是否显示内容区区

            },
            // 图像样式
            series: [
                {
                    name: '市场分布',
                    type: 'map',
                    mapType: 'china',
                    // hoverable: false, // 禁止hover事件
                    roam: true, // 是否开启缩放和平移漫游
                    itemStyle: { // 区域样式
                        // 普通样式
                        normal: {
                            label: {show: true},
                            borderWidth: .5, // 区域边框宽度
                            borderColor: '#0550c3', // 区域边框颜色
                            areaColor: "#4ea397", // 区域颜色
                        },
                        // hover样式
                        emphasis: {
                            label: {show: true},
                            borderColor: '#4b0082',
                            areaColor: "#ece39e",
                        }
                    },
                    data: []
                }
            ],
            animation: false
        };
        var provArr = ['上海', '河北', '山西', '内蒙古', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '江西', '山东', '河南', '湖北', '湖南', '广东', '广西', '海南', '四川', '贵州', '云南', '西藏', '陕西', '甘肃', '青海', '宁夏', '新疆', '北京', '天津', '重庆', '香港', '澳门'];//获取的省份，有可能是从后台获取
        option.series[0].data = provArr;//将拼接好的数组赋给参数集合
        mycharts.setOption(option);//跟新图表
        var geoJson = {}

        var parentInfo = [{
            cityName: '全国',
            code: 1000
        }];

        function init(adcode) {
            getGeoJson(adcode).then((data) => {
                geoJson = data
                getMapData(adcode)
            })
        };

        //这里我封装了下，直接可以拿过来用
        function getGeoJson(adcode, childAdcode = '') {
            return new Promise((resolve, reject) => {
                function insideFun(adcode, childAdcode) {
                    if (adcode === 1000) {
                        $.get('./geojson/china.json', function (geoJson) {
                            let mapJson = geoJson
                            resolve(mapJson);
                        })
                    } else if (adcode === 420000) {
                        $.get('./geojson/hubei.json', function (geoJson) {
                            let mapJson = geoJson
                            resolve(mapJson);
                        })
                    } else if ((adcode.toString()).slice(0, 2) == 42) {
                        $.get('./geojson/hubei.json', function (geoJson) {
                            let mapJson = geoJson
                            resolve(mapJson);
                        })
                    }
                }

                insideFun(adcode, childAdcode);
            });
        }

        //获取数据
        function getMapData(adcode) {
            let mapData = [],
                pointData = [],
                sum = 0
            geoJson.features.forEach(item => {
                let value = 288
                if (item.properties.adcode === adcode) {
                    if (addCode == adcode) {
                        value = 0;
                        addCode = 0;
                        if (adcode===420100) {
                            isWuHan =false;
                            page.initData()
                        }
                    } else {
                        addCode = adcode;
                    }
                }
                if (item.properties.adcode !== adcode) {
                    value = 0
                }
                if (item.properties.adcode === 420000) {
                    value = 288
                }
                mapData.push({
                    name: item.properties.name,
                    value: value,
                    cityCode: item.properties.adcode
                })
                pointData.push({
                    name: item.properties.name,
                    value: value,
                    cityCode: item.properties.adcode
                })
                sum += value
            })
            initEchartMap(mapData, sum, pointData)
        }

        //渲染echarts
        function initEchartMap(mapData, sum, pointData) {
            var xData = [],
                yData = [];
            var min = mapData[mapData.length - 1].value
            mapData.forEach(c => {
                xData.unshift(c.name)
                yData.unshift(c.value)
            })
            //这里做个切换，全国的时候才显示南海诸岛  只有当注册的名字为china的时候才会显示南海诸岛
            echarts.registerMap(parentInfo.length === 1 ? 'china' : 'map', geoJson);
            var option = {

                baseOption: {
                    backgroundColor: '#012248',
                    grid: {
                        right: '2%',
                        top: '12%',
                        bottom: '8%',
                        width: '20%'
                    },

                    geo: {
                        map: parentInfo.length === 1 ? 'china' : 'map',
                        zoom: parentInfo.length === 1 ? 1.6 : 1.0,
                        roam: false,
                        left: parentInfo.length === 1 ? '23%' : '16%',
                        top: parentInfo.length === 1 ? '27%' : '5%',

                        label: {
                            normal: {
                                show: true,
                                color: "#ffffff", //省份标签字体颜色
                                formatter: p => {
                                    switch (p.name) {
                                        case '内蒙古自治区':
                                            p.name = "内蒙古"
                                            break;
                                        case '西藏自治区':
                                            p.name = "西藏"
                                            break;
                                        case '新疆维吾尔自治区':
                                            p.name = "新疆"
                                            break;
                                        case '宁夏回族自治区':
                                            p.name = "宁夏"
                                            break;
                                        case '广西壮族自治区':
                                            p.name = "广西"
                                            break;
                                        case '香港特别行政区':
                                            p.name = "香港"
                                            break;
                                        case '澳门特别行政区':
                                            p.name = "澳门"
                                            break;

                                    }
                                    return p.name;
                                }
                            },
                            emphasis: {
                                show: true,
                                color: '#ffffff',
                            }
                        },
                        itemStyle: {
                            normal: {
                                areaColor: 'rgba(10,36,54,0.4)',
                                borderColor: '#65faf5',
                                borderWidth: 2.3,
                                shadowBlur: 15,
                                shadowColor: '#95e2ee',
                                shadowOffsetX: 7,
                                shadowOffsetY: 6,
                            },
                            emphasis: {
                                areaColor: '#50e1f6',
                                borderWidth: 1.6,
                                shadowBlur: 25,
                            }

                        },
                    },
                    xAxis: {
                        type: 'value',
                        scale: true,
                        position: 'top',
                        boundaryGap: false,
                        splitLine: {
                            show: false
                        },
                        axisLine: {
                            show: false,
                            lineStyle: {
                                color: '#455B77'
                            }
                        },
                        axisTick: {
                            show: false
                        },
                        axisLabel: {
                            margin: 2,
                            textStyle: {
                                color: '#c0e6f9'
                            }
                        },
                    },
                    visualMap: {
                        calculable: false,
                        inRange: {
                            min: 0,
                            max: 300,
                            color: ["rgba(10,36,54,0.4)", "#f58c3c"]
                        },
                    },
                    series: [{
                        type: 'map',
                        geoIndex: 0,
                        map: parentInfo.length === 1 ? 'china' : 'map',
                        roam: false,
                        zoom: 1.3,
                        label: {
                            normal: {
                                show: false,
                            },
                            emphasis: {
                                show: false,
                            }
                        },
                        data: mapData,

                    },

                    ]

                },


            }

            var myChart = echarts.init(document.getElementById('map-container'), null, {devicePixelRatio: 2.5});
            myChart.setOption(option, true)


        };
        //点击前解绑，防止点击事件触发多次
        mycharts.off('click');
        mycharts.on('click', echartsMapClick);

        init(1000);
        $(".first-title").html(title)

        //echarts点击事件
        function echartsMapClick(params) {
            if (!params.data) {
                return
            } else {
                //如果当前是最后一级，那就直接return
                if (parentInfo[parentInfo.length - 1].code === params.data.cityCode) {
                    return
                }
                let data = params.data
                init(data.cityCode)
                // addCode = data.cityCode
                if (data.cityCode === 420000) {
                    title = "湖北省大数据平台";
                    $(".first-title").html(title);
                    page.initData()
                    parentInfo.push({
                        cityName: data.name,
                        code: data.cityCode
                    })
                }
                isWuHan = false
                if (data.cityCode === 420100) {
                    isWuHan = true
                    page.initData();
                }
            }
        };
        $('.top_img').click(function () {
            if (parentInfo.length === 1) {
                return;
            }
            parentInfo.pop()
            title = "中国大数据平台";
            isWuHan = false
            page.initData();
            $(".first-title").html(title)
            init(parentInfo[parentInfo.length - 1].code)
        })
        page.initData();

    };

    /*******************************end 地图*****************************************/

    /*******************************方法统一调用*****************************************/
    // 初始化时间
    page.createTime();
    // 统一获取数据,需要根据地区进行筛选
    page.initData = function () {
        page.getAgeData()
        page.getSexData()
        page.inOutHosCount(); // 患者总数
        page.getDiseaseAnalyse();
        page.getDataIntegrity()
        page.getOperationRate()
        page.getHypertension()
        page.getRangeList()
        page.loadData();
    };
    page.areaDraw();
    $(".t1").on("click", {}, function () {
        lineType = 'wek'
        page.loadData(lineType);
        $(".t1").addClass('active-time');
        $(".t2").removeClass('active-time');
        $(".t3").removeClass('active-time');
    })
    $(".t2").on("click", {}, function () {
        lineType = 'mon'
        page.loadData(lineType);
        $(".t2").addClass('active-time');
        $(".t1").removeClass('active-time');
        $(".t3").removeClass('active-time');
    })
    $(".t3").on("click", {}, function () {
        lineType = 'year'
        page.loadData(lineType);
        $(".t3").addClass('active-time');
        $(".t1").removeClass('active-time');
        $(".t2").removeClass('active-time');
    })
});




